import store from 'store'
//import { getBaseUrl } from './host'
//import { getLanguage } from '../Framework/language/index'

let request = ({
                 url,
                 methods,
                 data={},
                 header,
                 noToken,
                 //baseUrl='http://47.74.30.152:3500/api/', //test
				 baseUrl = 'http://101.33.68.195:3502/api/',//main
				        useDefaultWallet = true,
               }) => {
  return new Promise((resolve, reject) => {
    console.log('Request is called');
    if(baseUrl){
      const address = store?.state?.defaultWallet?.address ?? ''
	  if(useDefaultWallet && address){
		  data.address = address;
	  }
      uni.request({
        url: (baseUrl) + url,
        method: methods,
        data: {...data},
        header: header || {
					'content-type': 'application/x-www-form-urlencoded',
				},
        success: (res) => {
		//console.log('res',res);
		  
		  // 47错误
		  if(res.data.code == -1){
		  	uni.showToast({
		  		title: res.data.message ?? '部分数据异常',
		  		icon: 'none'
		  	});
			reject(res.data);
			
		  } else if (res.data.code == 0) {
			// 47正确
            resolve(res.data)
			
          } else if (res.data.code == 200 || res.data.code == 1) {
			// 8.135 或者其他正确 // 1是php部分
		    resolve(res.data)
			
		  } else {
            uni.showToast({
              title: res?.data?.message ?? '',
              icon: 'none'
            });
            reject(res.data);
          }
        },
        fail: (err) => {
          console.log('###request failure');
          reject(err)
        }
      })
    }

  })
}

export default request;
